package com.SpringMVC.handlerInteceptor;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Controller拦截器
 */
public class TestHandlerInteceptor implements HandlerInterceptor{
    //进入Controllr前执行
    @Override
    public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
        System.out.println("testHandlerInteceptor......preHandle.....");
        return true;
    }

    //执行Controller业务逻辑后，视图渲染前执行（这里还可以对MODELANDVIEW的MODEL进行修改）
    @Override
    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
        System.out.println("testHandlerInteceptor......postHandle.....");
    }

    //视图渲染后执行
    @Override
    public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
        System.out.println("testHandlerInteceptor......afterCompletionHandle.....");
    }
}
